package fr.alma.domo.music.rc;

import fr.alma.domo.model.AbstractService;
import fr.alma.domo.model.Property;
import fr.alma.domo.music.PositionService;

@SuppressWarnings("serial")
public class HP extends AbstractService{

	private static long _ID = 0;
	public final long id = _ID++;
	
	/**
	 * La position du haut parleur
	 */
	@Property(type=String.class)
	public final static String POSITION="HP#position";
	
	/**
	 * Indicateur d'activité du haut parleur
	 */
	@Property(type=Boolean.class)
	public final static String BUSY = "HP#busy";
	
	/**
	 * Indique si le HP est fonctionnelle ou en panne
	 */
	@Property(type=Boolean.class,fragile=true)
	public final static String WORKING = "HP#working";
	
	/**
	 * Permet de transferer le son vers un autre haut parleur
	 * Si sa valeur passe de {@code PositionService.NO_POSITION} à une autre
	 * position connue, on essayera de trouver un haut parleur à cette position
	 * pour lui envoyer le son
	 */
	@Property(type=String.class,fragile=true)
	public final static String SOUND_TRANSFER_NEED = "HP#sound-transfer";
	
	public HP(){	
		super("HP");
		setBusy(false);
		setWorking(true);
	}
	
	public HP(String position){
		super("HP");
		setPosition(position);
		setBusy(false);
		setWorking(true);
		setAttribute(SOUND_TRANSFER_NEED, PositionService.NO_POSITION);
	}
	
	
	public String getPosition() {
		return getAttribute(POSITION,String.class);
	}

	public void setPosition(String position) {
		this.setAttribute(POSITION, position);
	}
	
	public boolean isBusy() {
		return getAttribute(BUSY,Boolean.class);
	}

	public void setBusy(boolean buzy) {
		setAttribute(BUSY,(Boolean)buzy);
	}

	public boolean isWorking(){
		return getAttribute(WORKING,Boolean.class);
	}
	
	public void setWorking(boolean working){
		setAttribute(WORKING,(Boolean)working);
	}
	
	public void transferSoundTo(String newPosition){	
		setAttribute(SOUND_TRANSFER_NEED, newPosition);
	}
	
	@Override
	public String toString(){
		return "HP"+id+"<"+getPosition()+">";		
	}
	
	@Override
	public boolean equals(Object o){
		if(o!=null && o instanceof HP){
			return id==((HP)o).id;
		}
		return false;
	}
	
}
